var prefix_path="http://123.56.219.116:8080/virtualcat/manage/user/";
var openid=getQueryString("openid");

$(function () {
    ajax_detail();
});

function ajax_detail() {
    $.ajax({
        url:prefix_path+"findById",
        type:"GET",
        dataType:"json",
        data:"openid="+openid,
        success:function (data) {
            if(data.data.msg=="login"){
                alert("请先登录");
                location.href="login.html";
                return;
            }
            console.info(data);
            if (data.code == 0){
                $("span[name='nickName']").html(data.data.userInfo.nickName);
                if (data.data.userInfo.sex==1){
                    $("span[name='sex']").html("男");
                }else{
                    $("span[name='sex']").html("女");
                }
                $("span[name='openid']").html(data.data.userInfo.openid);
                $("span[name='history']").html(data.data.userInfo.history);
                $("span[name='loginTime']").html(data.data.userInfo.obtain);
                if(data.data.userInfo.cname != null){
                    $("span[name='catId']").html(data.data.userInfo.catid);
                    $("span[name='catName']").html(data.data.userInfo.cname);
                    $("input[name='growth']").val(data.data.userInfo.growth);
                    $("input[name='feedCount']").val(data.data.userInfo.feedCount);
                    $("input[name='catFood']").val(data.data.userInfo.cfood);
                    $("input[name='discover']").val(data.data.userInfo.discover);
                    $("input[name='share']").val(data.data.userInfo.shareCount);
                    $("span[name='feedTime']").html(data.data.userInfo.feedTime);
                }
            }else{
                alert("无信息");
            }
        },
        error:function () {
            alert("网络错误");
        }
    })
}

function updateUser() {
    $.ajax({
        url:prefix_path+"updateUserInfo",
        type:"POST",
        contentType:'application/json',
        dataType:"json",
        data:JSON.stringify({
            "history":$("span[name='history']").html(),
            "openid":$("span[name='openid']").html(),
            "catid":$("span[name='catId']").html(),
            "growth":$("input[name='growth']").val(),
            "cfood":$("input[name='catFood']").val(),
            "feedCount":$("input[name='feedCount']").val(),
            "shareCount":$("input[name='share']").val(),
            "discover":$("input[name='discover']").val()
        }),
        success:function (data) {
            console.info(data);
            if(data.code == 0){
                alert("修改成功");
            }else{
                alert("修改失败");
            }
        },
        error:function () {
            alert("网络错误");
        }
    })
}